package com.example.myapplication.shortvideo.view;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.shortvideo.adapter.BaseVideoView;
import com.example.myapplication.shortvideo.bean.VideoListBean;
import com.example.myapplication.shortvideo.contract.VideoContract;
import com.example.myapplication.shortvideo.utils.DoubleClick;
import com.example.myapplication.shortvideo.utils.ImageUtil;


/**
 * @Description:
 * @Author: rongfeng
 * @CreateDate: 10:50
 */
public class VideoView extends BaseVideoView {
    protected ImageView img_likeState, img_share;
    protected ImageView img_cover;
    protected FrameLayout container;
    protected TextView tv_like_number, tv_share_number, tv_video_name, tv_video_tag, tv_voice_name;
    protected LinearLayout ll_like, ll_share, ll_details, ll_comment;
    protected RelativeLayout rl_root;
    protected  View  view_blank;
    protected Context context;

    public VideoView(View view) {
        super(view);
        img_cover = view.findViewById(R.id.img_cover);
        img_likeState = view.findViewById(R.id.img_likeState);
        img_share = view.findViewById(R.id.img_share);
        container = view.findViewById(R.id.container);
        tv_like_number = view.findViewById(R.id.tv_like_number);
        tv_share_number = view.findViewById(R.id.tv_share_number);
        tv_video_name = view.findViewById(R.id.tv_video_name);
        tv_video_tag = view.findViewById(R.id.tv_video_tag);
        ll_like = view.findViewById(R.id.ll_like);
        ll_share = view.findViewById(R.id.ll_share);
        ll_details = view.findViewById(R.id.ll_details);
        ll_comment = view.findViewById(R.id.ll_comment);
        rl_root = view.findViewById(R.id.rl_root);
        tv_voice_name = view.findViewById(R.id.tv_voice_name);
        view_blank = view.findViewById(R.id.view_blank);
    }

    private VideoContract mContract;
    private int position;
    private DoubleClick mPlayDoubleClick;

    @Override
    public void setContent(Context context, Object data, VideoContract contract, int position) {
        mContract = contract;
        VideoListBean.DataBean.RowsBean info = (VideoListBean.DataBean.RowsBean) data;
        ImageUtil.display(info.getVideoCover(), img_cover, 0);
        tv_voice_name.setSelected(true);

        ll_comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mContract.clickVideoComment();
            }
        });

        if (mPlayDoubleClick != null) {
            mPlayDoubleClick.release();
        }
        mPlayDoubleClick = DoubleClick.setDoubleClickListener(view_blank, 300, new DoubleClick.DoubleClickListener() {
            @Override
            public void click() {
                mContract.videoOnceClick();
            }

            @Override
            public void doubleClick() {
                mContract.videoDoubleClick();
            }
        });
    }

}
